// Copyright (C) 2010  Joan Puigcerver Perez, <joapuipe@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef __LOGUTILS_HPP__
#define __LOGUTILS_HPP__

#include <iostream>
#include <string>
#include <ctime>
#include <cc++/thread.h>

/** This mutex should be used with output operations to LOG files. */
static ost::Mutex LOGmutex;

/** This function obtains the current machine time and date as a string. Format: "Y/m/d H:M:S". */
extern std::string get_datetime(void);

/** 
 * This function prints a line to a logfile.
 * @param line Line to print (this line is preceded by the current date and time).
 * @param logf Output stream where the line is going to be printed.
 * @param mutex Mutex used to assure that no other line is printed at the same moment. 
 */
extern void print_log_line(const std::string& line, std::ostream& logf = std::cout, ost::Mutex& mutex = LOGmutex);

#endif
